﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../../script/ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />
    <link href="../../style/css/tool-icon-16.css" rel="stylesheet" type="text/css" />
    <script src="../../script/ext/adapter/jquery/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="../../script/ext/adapter/jquery/ext-jquery-adapter.js" type="text/javascript"></script>
    <script src="../../script/ext/ext-all.js" type="text/javascript"></script>
    <script src="../../script/ext/src/locale/ext-lang-zh_CN.js" type="text/javascript"></script>
    <!---->
    <title>角色管理</title>
    <script type="text/javascript">
        Ext.BLANK_IMAGE_URL = '/script/ext/resources/images/s.gif';
        Ext.onReady(function () {
            Ext.QuickTips.init();

            //创建根节点
            var CompanyTreeRoot = new Ext.tree.AsyncTreeNode({ text: '信息分类树', id: 'CompanyTreeRoot', expanded: true, leaf: false });
            //创建树面板
            var CompanyTree = new Ext.tree.TreePanel({
                loader: new Ext.tree.TreeLoader({ dataUrl: "SERVER/user/CDDSelectTree.aspx" }),
                id: 'CompanyTree',
                region: 'west',
                split: true,
                width: 240,
                minSize: 240,
                maxSize: 300,
                collapsible: true,
                margins: '5 0 5 5',
                cmargins: '5',
                rootVisible: false,
                lines: true,
                autoScroll: true,
                enableDD: true,
                title: "信息分类",
                tbar: [{ iconCls: 'icon-expand-all',
                    tooltip: '全部展开',
                    handler: function () {
                        CompanyTreeRoot.expand(true);
                    }
                }, { iconCls: 'icon-collapse-all',
                    tooltip: '全部折叠',
                    handler: function () {
                        CompanyTreeRoot.collapse(true);
                    }
                }, { iconCls: 'iocn-all',
                    tooltip: '全选',
                    handler: function () {
                        CompanyTreeRoot.eachChild(function (child) {
                            child.ui.toggleCheck(true);
                            child.attributes.checked = true;
                            child.fireEvent('checkchange', child, true);
                        });
                    }
                }, { iconCls: 'iocn-noall',
                    tooltip: '取消全部',
                    handler: function () {
                        CompanyTreeRoot.eachChild(function (child) {
                            child.ui.toggleCheck(false);
                            child.attributes.checked = false;
                            child.fireEvent('checkchange', child, false);
                        });
                    }
                }, { iconCls: 'iocn-noall',
                    tooltip: '添加同级节点',
                    handler: function () {
                    }
                }, { iconCls: 'iocn-collapse-all',
                    tooltip: '添加子节点',
                    handler: function () {
                    }
                }, { iconCls: 'iocn-noall',
                    tooltip: '编辑节点',
                    handler: function () {
                    }
                }, { iconCls: 'iocn-collapse-all',
                    tooltip: '删除节点',
                    handler: function () {
                    }
                }, { iconCls: 'iocn-collapse-all',
                    tooltip: '按所选节点分组检索用户信息',
                    text: "检索",
                    handler: function () {
                        var ck = CompanyTree.getChecked();
                        var checkid = new Array; //存放选中id的数组
                        for (var i = 0; i < ck.length; i++) {
                            checkid.push(ck[i].id); //添加id到数组
                        }
                        alert(checkid.toString());
                        //                        grid.setTitle(node.text + ":" + "用户信息");
                        //                        groupStore.load({ params: { start: 0, limit: pageSize, key: node.id} });
                        //                        $("#roleId").val(node.id);
                    }
                }]
            });
            CompanyTree.setRootNode(CompanyTreeRoot);
            CompanyTree.on('checkchange', function (node, checked) {
                node.expand();
                node.attributes.checked = checked;
                node.eachChild(function (child) {
                    child.ui.toggleCheck(checked);
                    child.attributes.checked = checked;
                    child.fireEvent('checkchange', child, checked);
                });
            }, CompanyTree);
            //定义请求参数
            var proxy = new Ext.data.HttpProxy({ url: "SERVER/User/UserList.aspx" });
            //定义数据模型
            var UserInfo = new Ext.data.Record.create([
                        { name: 'ID', type: 'int', mappging: "ID" },
                        { name: 'Account', type: 'string', mappging: "Account" },
                        { name: 'Name', type: 'string', mappging: "Name" },
                        { name: 'TrueName', type: 'string', mappging: "TrueName" },
                        { name: 'EmailAddress', type: 'string', mappging: "EmailAddress" },
                        { name: 'CompanyID', type: 'int', mappging: "CompanyID" },
                        { name: 'DepmetID', type: 'int', mappging: "DepmetID" },
                        { name: 'IsRole', type: 'bool', mappging: "IsRole" }
                        ]);

            //创建阅读器
            var reader = new Ext.data.JsonReader({ totalProperty: "Count", root: "List" }, UserInfo);
            var formReader = new Ext.data.JsonReader({}, UserInfo);

            //创建数据源
            var groupStore = new Ext.data.GroupingStore({
                proxy: proxy,
                reader: reader,
                sortInfo: { field: 'ID', direction: 'DESC' }
            });

            //设置每页条数
            var pageSize = 20;
            var cookiePageSize = parseInt(Ext.util.Cookies.get("pageSize"));
            if (cookiePageSize) { pageSize = cookiePageSize; }

            //加载数据源
            groupStore.load({ params: { start: 0, limit: pageSize} });

            //创建选择列模型
            var sm = new Ext.grid.CheckboxSelectionModel();

            //定义列模型
            var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), sm, {
                id: 'ID',
                header: '编号',
                dataIndex: 'ID',
                width: 60,
                sortable: true
            }, {
                id: 'Account',
                header: '帐号',
                dataIndex: 'Account',
                width: 100,
                sortable: true
            }, {
                header: '姓名',
                dataIndex: 'TrueName',
                width: 80,
                sortable: true
            }, {
                header: '昵称',
                dataIndex: 'Name',
                width: 80,
                sortable: true
            }, {
                header: '公司',
                dataIndex: 'CompanyID',
                width: 100,
                sortable: true
            }, {
                header: '部门',
                dataIndex: 'DepmetID',
                width: 100,
                sortable: true
            }, {
                xtype: 'booleancolumn',
                header: '色分权限',
                dataIndex: 'IsRole',
                width: 72,
                trueText: '<b class="yes"></b>',
                falseText: '<b class="no"></b>'
            }, {
                id: "EmailAddress",
                header: '电子邮箱',
                dataIndex: 'EmailAddress',
                width: 100,
                sortable: true
            }]);

            //创建下[每页行数]拉框
            var comboBox = new Ext.form.ComboBox({
                width: 60,
                typeAhead: true,
                triggerAction: 'all',
                lazyRender: true,
                mode: 'local',
                title: "每页行数",
                emptyText: pageSize,
                store: new Ext.data.ArrayStore({
                    id: 0,
                    fields: ['myId', 'displayText'],
                    data: [[10, 10], [20, 20], [30, 30], [50, 50], [100, 100]]
                }),
                valueField: 'myId',
                displayField: 'displayText'
            }); comboBox.on("select", function (combo, record, index) {
                Ext.util.Cookies.set("pageSize", record.id);
                window.location.reload();
            });

            //创建[用户信息]表格
            var grid = new Ext.grid.GridPanel({
                title: "信息列表",
                store: groupStore,
                border: true,
                margins: '5 0 5 0',
                region: 'center',
                autoExpandColumn: "EmailAddress",
                view: new Ext.grid.GroupingView(),
                sm: sm,
                cm: cm,
                tbar: [{
                    iconCls: 'iocn-useradd',
                    text: '添加',
                    handler: function (btn) { upUser(btn, "0"); }
                }, {
                    ref: '../removeBtn',
                    iconCls: 'iocn-userdel',
                    text: '删除',
                    disabled: true,
                    handler: function () {
                        Ext.MessageBox.confirm("确认提示", "确认要删除所选行数据？", function (btn) {
                            if (btn == "yes") {
                                var s = grid.getSelectionModel().getSelections();
                                var delR = new Array();
                                var delRid = new Array();
                                for (var i = s.length - 1; i >= 0; i--) {
                                    var r = s[i];
                                    if (r.get('ID') != undefined) { delRid.push(r.get('ID')); delR.push(r); }
                                }
                                Ext.Ajax.request({
                                    url: "SERVER/User/UserDel.aspx",
                                    method: 'POST',
                                    params: { id: delRid },
                                    success: function (response) {
                                        var json = Ext.util.JSON.decode(response.responseText);
                                        if (json.success) {
                                            for (var i = 0; i < delR.length; i++) {
                                                if (json.ids.valueOf(delR[i].get('ID'))) { groupStore.remove(delR[i]) }
                                            }
                                            Ext.Msg.alert("提示", "已删除" + json.count + "行<br/>" + json.msg);
                                        } else {
                                            Ext.Msg.alert("错误", json.error);
                                        }
                                    }
                                });
                            }
                        });
                    }
                }],
                bbar: new Ext.PagingToolbar({
                    store: groupStore,
                    pageSize: pageSize,
                    displayInfo: true,
                    prependButtons: true,
                    items: ['每页行数', comboBox, '-'],
                    displayMsg: "本页显示第{0}条到第{1}条数据，共{2}条",
                    emptyMsg: "暂无记录"
                })
            });

            //部门下拉列表
            var DepmetComboBoxTree = new Ext.form.ComboBoxTree({
                width: 200,
                name: "myDepmetId",
                fieldLabel: "所属部门",
                hiddenName: "DepmetID",
                listEmptyText: "*暂无部门信息*",
                emptyText: "请选择部门",
                editable: false,
                resizable: true,
                tree: new Ext.tree.TreePanel({
                    root: new Ext.tree.AsyncTreeNode({ text: '部门', id: '0', leaf: false, checked: false }),
                    lines: true,
                    rootVisible: false,
                    border: false,
                    dataUrl: 'SERVER/User/DepmetTree.aspx?cid=1',
                    listeners: {
                        beforeload: function (n) { if (n) { this.getLoader().baseParams.id = n.attributes.id; } }
                    }
                })
            });
            //公司下拉列表
            var CompanyComboBoxTree = new Ext.form.ComboBoxTree({
                width: 200,
                name: "myCompanyId",
                fieldLabel: "所属公司",
                hiddenName: "CompanyID",
                listEmptyText: "*暂无公司信息*",
                emptyText: "请选择公司",
                editable: false,
                resizable: true,
                tree: new Ext.tree.TreePanel({
                    root: new Ext.tree.AsyncTreeNode({ text: '公司', id: '0', leaf: false, checked: false }),
                    rootVisible: false,
                    border: false,
                    lines: true,
                    dataUrl: 'SERVER/User/CompanyTree.aspx',
                    listeners: {
                        beforeload: function (n) { if (n) { this.getLoader().baseParams.id = n.attributes.id; } }
                    }
                })
            });
            //职务下拉列表
            var DutiesComboBox = new Ext.form.ComboBox({
                width: 200,
                name: "myDutiesId",
                fieldLabel: "所属职务",
                emptyText: "请选择职务", //默认值
                listEmptyText: "*暂无职务信息*",
                blankText: '请选择职务', //该项如果没有选择，则提示错误信息
                hiddenName: "DutiesID",
                triggerAction: 'all', // 显示所有下列数据，一定要设置属性triggerAction为all 
                forceSelection: true, //必须选择一个选项 
                editable: false,
                mode: 'remote',
                valueField: 'id', //值 
                displayField: 'name', //显示文本 
                store: new Ext.data.Store({
                    proxy: new Ext.data.HttpProxy({ url: "SERVER/User/DutiesList.aspx" }),
                    reader: new Ext.data.JsonReader({}, [{ name: 'id', type: 'int', mapping: "ID" }, { name: 'name', type: 'string', mapping: "Name"}]),
                    autoLoad: true
                })
            });

            //创建[用户信息]表单
            var UserForm = new Ext.form.FormPanel({
                region: 'east',
                split: true,
                width: 300,
                minSize: 300,
                maxSize: 300,
                collapsible: true,
                margins: '5 5 5 0',
                cmargins: '5',
                title: "编辑信息",
                bodyStyle: "padding:10px 5px;",
                labelAlign: "right",
                labelWidth: 65,
                buttonAlign: "center",
                defaultType: "textfield",
                border: true,
                items: [{
                    name: "Account",
                    fieldLabel: "用户编号",
                    width: 200,
                    value: 0
                }, {
                    name: "Account",
                    allowBlank: false,
                    regex: /^[a-zA-Z0-9_]{2,}$/,
                    invaildText: "输入结果无效",
                    fieldLabel: "登录帐号",
                    width: 200,
                    tooltip: "帐号格式：字母、数字和下划线并且至少输入两个字符以上[必填]",
                    tooltipType: "qtip"
                }, {
                    width: 200,
                    name: "Password",
                    allowBlank: false,
                    regex: /^\w{2,}$/,
                    invaildText: "输入结果无效",
                    fieldLabel: "登录密码",
                    inputType: "password",
                    tooltip: "密码格式：任意字符并两个字符以上[必填]",
                    tooltipType: "qtip"
                }, {
                    width: 200,
                    name: "TrueName",
                    allowBlank: false,
                    regex: /^\w{2,}$/,
                    invaildText: "输入结果无效",
                    fieldLabel: "真实姓名"
                }, {
                    width: 200,
                    name: "Name",
                    fieldLabel: "用户昵称",
                    regex: /^\w{2,}$/,
                    invaildText: "输入结果无效",
                    tooltip: "昵称格式：任意字符并两个字符以上[可空]",
                    tooltipType: "qtip"
                }, {
                    width: 200,
                    name: "EmailAddress",
                    fieldLabel: "电子邮箱",
                    vtype: "email",
                    invaildText: "输入结果无效"
                }, new Ext.form.ComboBox({
                    name: "IsRole",
                    width: 200,
                    fieldLabel: "验证方式",
                    emptyText: "请选择权限验证方式",
                    hiddenName: "isrole",
                    triggerAction: 'all', // 显示所有下列数据，一定要设置属性triggerAction为all 
                    forceSelection: true, //必须选择一个选项 
                    mode: 'local',
                    valueField: 'id',
                    displayField: 'text',
                    editable: false,
                    store: new Ext.data.ArrayStore({
                        id: "isRole",
                        fields: ['id', 'text'],
                        data: [["true", "基于角色"], ["false", "基于用户"]],
                        value: "true"
                    })
                }), CompanyComboBoxTree, DepmetComboBoxTree, DutiesComboBox],
                buttons: [{
                    text: "确定",
                    handler: function () {
                        if (account != "0") {
                        }
                        else {
                            UserForm.getForm().submit({
                                success: function (response) { Ext.Msg.alert("成功", "恭喜，表单提交成功"); },
                                failure: function (response) { Ext.Msg.alert("失败", "对不起，表单提交失败"); }
                            });
                        }
                    }
                }, {
                    text: "重置",
                    handler: function () { UserForm.getForm().reset(); }
                }]
            });

            //创建页面布局
            var viewport = new Ext.Viewport({ layout: 'border', items: [CompanyTree, grid, UserForm] });
            //布局加载
            viewport.doLayout();
            //延时加载
            setTimeout(function () { Ext.get('loading').remove(); Ext.get('loading-mask').fadeOut({ remove: true }); }, 400);

            //有选择行启用删除按钮
            grid.getSelectionModel().on('selectionchange', function (sm) { grid.updataBtn.setDisabled(sm.getCount() != 1); grid.removeBtn.setDisabled(sm.getCount() < 1); });
        });
    </script>
</head>
<body>
    <div id="loading-mask">
    </div>
    <div id="loading">
        <div class="loading-indicator">
            <img alt="" src="/style/images/extanim32.gif" style="margin-right: 8px; width: 32px; height: 32px;" align="absmiddle" />正在努力的加载...
        </div>
    </div>
</body>
</html>
